import req from "/@/api/req";
import {
  ApplyNumItem,
  CompleteWorkInfo,
  CompleteWorkOrder,
  ConstructionWorkInfo,
  DispatchWorkOrderItem,
  FlowNoeReq,
  FunctionMapperItem,
  RecordItem,
  ServiceWorkOrderReq,
  SigninInfo,
  SignInWorkOrder,
  SumItem,
  VisitRecordItem,
  WorkFlowNode,
  WorkOrderConstruction,
  WorkOrderInfo,
  WorkOrderItem,
  WorkOrderOperation,
} from "./models";

export enum Api {
  pageWorkOrders = "api/iopm/workOrdersPc/pageWorkOrders",
  summaryAdminTodoWorkOrdersForPc = "api/iopm/workOrdersSummary/summaryAdminTodoWorkOrdersForPc",
  summaryOperationTodoWorkOrdersForPc = "api/iopm/workOrdersSummary/summaryOperationTodoWorkOrdersForPc",
  dispatchWorkOrders = "api/iopm/workOrders/dispatchWorkOrders",
  createWorkOrders = "api/iopm/workOrders/createWorkOrders",
  cancleWorkOrders = "api/iopm/workOrders/cancleWorkOrders", // 服务申请单取消
  constructionWorkOrders = "api/iopm/workOrders/constructionWorkOrders",
  executeWorkOrders = "api/iopm/workOrders/executeWorkOrders",
  finishWorkOrders = "api/iopm/workOrders/finishWorkOrders",
  reassignmentWorkOrders = "api/iopm/workOrders/reassignmentWorkOrders",
  receivingWorkOrders = "api/iopm/workOrders/receivingWorkOrders",
  turnDispatchWorkOrders = "api/iopm/workOrders/turnDispatchWorkOrders",
  transferWorkOrders = "api/iopm/workOrders/transferWorkOrders",
  cancelServiceOrder = "api/iopm/serviceOrders/cancelServiceOrder",
  getWorkOrdersById = "api/iopm/workOrders/getWorkOrdersById",
  mapperWorkStateFunction = "api/iopm/workOrdersStateFunctionMapper/mapperWorkStateFunction",
  getWorkOrderRecords = "api/iopm/workOrderRecords/getWorkOrderRecords",
  saveConstructions = "api/iopm/workOrderConstructions/saveConstructions",
  saveCompleteds = "api/iopm/workOrderCompleteds/saveCompleteds",
  getWorkFlowNodes = "api/iopm/workFlowNodes/getWorkFlowNodes",
  signIn = "api/iopm/workOrderSignIns/signIn",
  refuseWorkOrders = "api/iopm/workOrders/refuseWorkOrders",
  addWorkOrderVisitRecords = "api/iopm/workOrderVisitRecords/addWorkOrderVisitRecords",
  getWorkOrderSignInsByWorkOrderId = "api/iopm/workOrderSignIns/getWorkOrderSignInsByWorkOrderId",
  getConstructionsByWorkOrderId = "api/iopm/workOrderConstructions/getConstructionsByWorkOrderId",
  getCompletedsByWorkOrderId = "api/iopm/workOrderCompleteds/getCompletedsByWorkOrderId",
  addWorkOrderComplaintVisitRecords = "api/iopm/workOrderComplaints/addWorkOrderComplaintVisitRecords",
  cancelReceivingWorkOrders = "api/iopm/workOrders/cancelReceivingWorkOrders",
  updateWorkOrdersOperations = "api/iopm/workOrders/updateWorkOrdersOperations",
  summaryTodoWorkOrders = "api/iopm/workOrdersSummary/summaryTodoWorkOrders",
}
// 获取签到信息
export function getWorkOrderSignInsByWorkOrderId(data: WorkOrderOperation) {
  return req.post<Array<SigninInfo>>(
    {
      url: Api.getWorkOrderSignInsByWorkOrderId,
      data,
    },
    {
      useGlobalLoading: false,
    }
  );
}
// 获取施工信息
export function getConstructionsByWorkOrderId(data: WorkOrderOperation) {
  return req.post<ConstructionWorkInfo>(
    {
      url: Api.getConstructionsByWorkOrderId,
      data,
    },
    {
      useGlobalLoading: false,
    }
  );
}
// 获取完工信息
export function getCompletedsByWorkOrderId(data: WorkOrderOperation) {
  return req.post<CompleteWorkInfo>(
    {
      url: Api.getCompletedsByWorkOrderId,
      data,
    },
    {
      useGlobalLoading: false,
    }
  );
}
// 退回工单
export function cancelReceivingWorkOrders(data: WorkOrderOperation) {
  return req.post<CompleteWorkInfo>(
    {
      url: Api.cancelReceivingWorkOrders,
      data,
    },
    {
      useGlobalLoading: false,
    }
  );
}
// 服务回访
export function addWorkOrderVisitRecords(data: VisitRecordItem) {
  return req.post<Boolean>(
    {
      url: Api.addWorkOrderVisitRecords,
      data,
    },
    {
      useGlobalLoading: false,
    }
  );
}
// 签到工单
export function signIn(data: SignInWorkOrder) {
  return req.post<Boolean>(
    {
      url: Api.signIn,
      data,
    },
    {
      useGlobalLoading: false,
    }
  );
}
// 完工工单
export function saveCompleteds(data: CompleteWorkOrder) {
  return req.post<Boolean>(
    {
      url: Api.saveCompleteds,
      data,
    },
    {
      useGlobalLoading: false,
    }
  );
}
// 施工工单
export function saveConstructions(data: WorkOrderConstruction) {
  return req.post<Boolean>(
    {
      url: Api.saveConstructions,
      data,
    },
    {
      useGlobalLoading: false,
    }
  );
}
// 拒接工单
export function refuseWorkOrders(data: WorkOrderOperation) {
  return req.post<Array<WorkFlowNode>>(
    {
      url: Api.refuseWorkOrders,
      data,
    },
    {
      useGlobalLoading: false,
    }
  );
}
// 获取工单服务记录
export function getWorkOrderRecords(data: WorkOrderOperation) {
  return req.post<Array<WorkFlowNode>>(
    {
      url: Api.getWorkOrderRecords,
      data,
    },
    {
      useGlobalLoading: false,
    }
  );
}
// 获取工单服务记录
export function getWorkFlowNodes(data: WorkOrderOperation) {
  return req.post<FlowNoeReq>(
    {
      url: Api.getWorkFlowNodes,
      data,
    },
    {
      useGlobalLoading: false,
    }
  );
}
// 功能映射
export function mapperWorkStateFunction() {
  return req.post<Array<FunctionMapperItem>>(
    {
      url: Api.mapperWorkStateFunction,
    },
    {
      useGlobalLoading: false,
    }
  );
}
// 取消申请工单
export function cancleWorkOrders(data: WorkOrderOperation) {
  return req.post<boolean>(
    {
      url: Api.cancleWorkOrders,
      data,
    },
    {
      useGlobalLoading: false,
    }
  );
}
// 获取工单详情
export function getWorkOrdersById(data: WorkOrderOperation) {
  return req.post<WorkOrderInfo>(
    {
      url: Api.getWorkOrdersById,
      data,
    },
    {
      useGlobalLoading: false,
    }
  );
}
// 取消服务申请
export function cancelServiceOrder(data: WorkOrderOperation) {
  return req.post<boolean>(
    {
      url: Api.cancelServiceOrder,
      data,
    },
    {
      useGlobalLoading: false,
    }
  );
}
// 施工工单
export function constructionWorkOrders(data: WorkOrderOperation) {
  return req.post<boolean>(
    {
      url: Api.constructionWorkOrders,
      data,
    },
    {
      useGlobalLoading: false,
    }
  );
}
// 派单
export function dispatchWorkOrders(data: DispatchWorkOrderItem) {
  return req.post<boolean>(
    {
      url: Api.dispatchWorkOrders,
      data,
    },
    {
      useGlobalLoading: false,
    }
  );
}
// 执行工单
export function executeWorkOrders(data: WorkOrderOperation) {
  return req.post<boolean>(
    {
      url: Api.executeWorkOrders,
      data,
    },
    {
      useGlobalLoading: false,
    }
  );
}
// 完工工单
export function finishWorkOrders(data: WorkOrderOperation) {
  return req.post<boolean>(
    {
      url: Api.finishWorkOrders,
      data,
    },
    {
      useGlobalLoading: false,
    }
  );
}
// 接单工单
export function receivingWorkOrders(data: WorkOrderOperation) {
  return req.post<boolean>(
    {
      url: Api.receivingWorkOrders,
      data,
    },
    {
      useGlobalLoading: false,
    }
  );
}
// 改派工单
export function reassignmentWorkOrders(data: DispatchWorkOrderItem) {
  return req.post<boolean>(
    {
      url: Api.reassignmentWorkOrders,
      data,
    },
    {
      useGlobalLoading: false,
    }
  );
}

export function summaryAdminTodoWorkOrdersForPc(data) {
  return req.post<SumItem>(
    {
      url: Api.summaryAdminTodoWorkOrdersForPc,
      data,
    },
    {
      useGlobalLoading: false,
    }
  );
}
// 创建工单
export function createWorkOrders(data: WorkOrderItem) {
  return req.post<WorkOrderItem>(
    {
      url: Api.createWorkOrders,
      data,
    },
    {
      useGlobalLoading: false,
    }
  );
}
// 转工单(工单创建)
export function transferWorkOrders(data: WorkOrderItem) {
  return req.post<boolean>(
    {
      url: Api.transferWorkOrders,
      data,
    },
    {
      useGlobalLoading: false,
    }
  );
}
// 转派工单
export function turnDispatchWorkOrders(data: WorkOrderItem) {
  return req.post<boolean>(
    {
      url: Api.turnDispatchWorkOrders,
      data,
    },
    {
      useGlobalLoading: false,
    }
  );
}
export function summaryOperationTodoWorkOrdersForPc(data) {
  return req.post<SumItem | null>(
    {
      url: Api.summaryOperationTodoWorkOrdersForPc,
      data,
    },
    {
      useGlobalLoading: false,
    }
  );
}
export function summaryTodoWorkOrders(data: { equipmentIds?: string[]; projectIds?: string[]; workRoleType?: string }) {
  return req.post<SumItem | null>(
    {
      url: Api.summaryTodoWorkOrders,
      data,
    },
    {
      useGlobalLoading: false,
    }
  );
}
export function pageWorkOrders(data: ServiceWorkOrderReq) {
  return req.post<Array<WorkOrderInfo>>(
    {
      url: Api.pageWorkOrders,
      data,
    },
    {
      useGlobalLoading: false,
    }
  );
}
